<?php


namespace app\api\controller;

use app\common\controller\Base as BaseCommon;
class Base extends BaseCommon
{
    public function initialize()
    {
        parent::initialize();

        //开启跨域
        if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
            //    //返回支持跨域头
            header("Access-Control-Allow-Origin: *");
            header("Access-Control-Allow-Headers:Origin,X-Requested-With,Content-Type,Accept,Authorization,Ver,System");
            header("Access-Control-Allow-Methods:GET,POST,PUT,DELETE,OPTIONS,PATCH");
            header("Access-Control-Max-Age:86400");//一天
            exit;
        }
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Credentials:true");
    }

    //快捷验证
    function validate(array $data, $validate='', array $message = [], bool $batch = false)
    {
        if($validate==''){
            $validate = $this->request->controller().'.'.$this->request->action();
        }
        return parent::validate($data, $validate, $message, $batch); // TODO: Change the autogenerated stub
    }
}